package com.tmp;

import com.bean.Student;
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * config排序
 *
 * @author: chenhs
 * @date: Created in 10:48 2022/1/21
 **/
public class RedpacketTest {
    public static Logger log = LoggerFactory.getLogger(RedpacketTest.class);

    public static void main(String[] args) {

        Student student1 = new Student("1-43EI25Z,1-TPFAQB",19,175);
        Student student11 = new Student("1-43EI25Z,1-TPFAQB",21,175);
        Student student12 = new Student("1-43EI25Z",21,175);
        Student student13 = new Student("1-43EI25Z",23,175);
        Student student2 = new Student("1-43MSKSL",18,165);
        Student student21 = new Student("1-43MSKSL,1-43EI25Z",18,165);
        Student student3 = new Student("1-N3MJQY",20,170);
        Student student4 = new Student("1-43H7MET",15,170);
        List<Student> studentList = Lists.newArrayList();
        studentList.add(student1);
        studentList.add(student2);
        studentList.add(student3);
        studentList.add(student4);
        studentList.add(student11);
        studentList.add(student12);
        studentList.add(student21);
        studentList.add(student13);
        log.info("未排序的list:{}",studentList);
//
//        //对年龄降序排序
//        List<Student> orderAgeDescList = studentList.stream().sorted(Comparator.comparing(Student::getAge).reversed()).collect(Collectors.toList());
//        log.info("对年龄降序排序后:{}",orderAgeDescList);
//
//        //对年龄升序排序
//        List<Student> orderAgeAscList = studentList.stream().sorted(Comparator.comparing(Student::getAge)).collect(Collectors.toList());
//        log.info("对年龄升序排序后:{}",orderAgeAscList);
//
//        //对年龄降序排序，对身高升序排序
//        List<Student> orderAgeDescAndHeightAscList = studentList.stream().sorted(Comparator.comparing(Student::getAge).reversed().thenComparing(Student::getHeight)).collect(Collectors.toList());
//        log.info("对年龄降序排序，对身高升序排序后:{}",orderAgeDescAndHeightAscList);
//

        //对年龄降序排序，对身高升序排序
        List<Student> orderNameDescAndHeightAscList = studentList.stream().sorted(Comparator.comparing(Student::getName).reversed().thenComparing(Student::getAge)).collect(Collectors.toList());
        List<Student> orderNameSizeDescList = orderNameDescAndHeightAscList.stream().sorted(Comparator.comparing(Student::getNameSize).reversed()).collect(Collectors.toList());

        log.info("对名字降序排序，对年龄升序排序后:{}", orderNameSizeDescList);


    }
}
